package work20241217;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author zdl
 * @date 2024/12/17
 */
public class Demo4_map {
    public static void main(String[] args) {
        String str = "abcHelloabcWorld";
        Map<String,Integer> map  = new HashMap<>();
        char[] charArray = str.toCharArray();
        for (char c : charArray) {
            String s = String.valueOf(c);
            boolean b = map.containsKey(s);
            if (!b){
                map.put(s,1);
            }else {
                Integer integer = map.get(s);
                integer++;
                map.put(s,integer);
            }
        }
        System.out.println(map);
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.print(entry.getKey()+"出现"+entry.getValue()+"次，");
        }

    }
}
